* Determine which days had broadcasts

clear all
set more off


import delim "out-data/program_dates.tsv", clear varn(1)

gen int date = date(dt, "YMD"), after(dt)
drop dt
format date %td
rename date dt

gen byte onair = !mi(program_id)
drop program_id
bys network dt: keep if _n == 1

// complete time series
encode network, gen(station)
xtset station dt, daily
tsfill, full
bys station (network): replace network = network[_N] if mi(network)
replace onair = 0 if mi(onair)

gen byte dow = dow(dt), after(dt)
gen int yr = year(dt), after(dt)
gen byte mon = month(dt), after(yr)

tab dow network if onair == 1, m

table yr network, c(sum onair)
table yr network if inrange(dow, 1, 5), c(sum onair)

table yr mon, c(mean onair)

order station network dt
la var station "Numeric network identifier"
la var network "Network initials"
la var dt "Date"
la var yr "Year"
la var dow "Day of week"
la var onair "Network had broadcast"
exit
